/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelOpcionesBeansAbstractList.java
 *
 * Created on 12-nov-2011, 17:07:57
 */
package com.ufps.cuatro.vistas.representacion;

import com.ufps.cuatro.controlador.render.UtilRender;
import com.ufps.cuatro.modelo.representacion.PropiedadBeans;
import com.ufps.cuatro.modelo.old.ComponenteBeans;
import com.ufps.cuatro.modelo.representacion.componente.ComponenteDistribuidor;
import com.ufps.cuatro.util.render.CheckListManager;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import org.jdesktop.application.Action;

/**
 *
 * @author Carlos A. Torres C. 
 */
public class JPanelOpcionesBeansAbstractList extends javax.swing.JPanel implements Observer{
    private static final long serialVersionUID = -3143512680501889836L;
    
    private Object objParent;
    private ComponenteDistribuidor objComponenteDistribuidor;
    private ArrayList<PropiedadBeans> objPropiedadesSimples;
    private ArrayList<ComponenteBeans> objPropiedadesCompuestas;
    private CheckListManager checkListManagerPropiedadesSimples;
    private CheckListManager checkListManagerPropiedadesCompuestas;

    /** Creates new form JPanelOpcionesBeansAbstractList */
    public JPanelOpcionesBeansAbstractList(Object objParent, ComponenteDistribuidor objComponenteDistribuidor) {
        initComponents();
        this.objParent = objParent;
        this.objComponenteDistribuidor = objComponenteDistribuidor;        
        loadPropiedades();
        this.jButtonAplicarToString.setEnabled(false);
        this.jButtonDelToString.setEnabled(false);
    }
    
    private void loadPropiedades(){
        objPropiedadesSimples = objComponenteDistribuidor.getObjComponenteBeans().getObjPropiedadesStaticSimpleBeans();
        objPropiedadesCompuestas = objComponenteDistribuidor.getObjComponenteBeans().getObjPropiedadesStaticObjectBeans();
        UtilRender.helperRenderJList(jListPropiedadesSimples, objPropiedadesSimples, 0);
        UtilRender.helperRenderJList(jListPropiedadesCompuestas, objPropiedadesCompuestas, 0);
        checkListManagerPropiedadesSimples = new CheckListManager(jListPropiedadesSimples); 
        checkListManagerPropiedadesCompuestas = new CheckListManager(jListPropiedadesCompuestas); 
//        MouseListener mouseListenerSimple = new MouseAdapter() {
//            @Override
//            public void mouseClicked(MouseEvent e) {
//                if (e.getButton() == MouseEvent.BUTTON1) {
//                    //Click izquierdo
//                    int posicion = jListPropiedadesSimples.locationToIndex(e.getPoint());
//                    Object objItem = objPropiedadesSimples.get(posicion);                    
//                    if(objItem instanceof PropiedadBeans){
//                        PropiedadBeans objPropiedadBeans = (PropiedadBeans) objItem;
//                        jTextFieldToStirng.setText(objPropiedadBeans.getName());
//                    }
//                    else if(objItem instanceof ComponenteBeans){
//                        ComponenteBeans objComponenteBeans = (ComponenteBeans) objItem;
//                        jTextFieldToStirng.setText(objComponenteBeans.getName());
//                    }
//                }
//            }
//        };
//        jListPropiedadesSimples.addMouseListener(mouseListenerSimple);
//        MouseListener mouseListenerCompuesto = new MouseAdapter() {
//            @Override
//            public void mouseClicked(MouseEvent e) {
//                if (e.getButton() == MouseEvent.BUTTON1) {
//                    //Click izquierdo
//                    int posicion = jListPropiedadesCompuestas.locationToIndex(e.getPoint());
//                    Object objItem = objPropiedadesCompuestas.get(posicion);
//                    if(objItem instanceof PropiedadBeans){
//                        PropiedadBeans objPropiedadBeans = (PropiedadBeans) objItem;
//                        jTextFieldToStirng.setText(objPropiedadBeans.getName());
//                    }
//                    else if(objItem instanceof ComponenteBeans){
//                        ComponenteBeans objComponenteBeans = (ComponenteBeans) objItem;
//                        jTextFieldToStirng.setText(objComponenteBeans.getName());
//                    }
//                }
//            }
//        };
//        jListPropiedadesCompuestas.addMouseListener(mouseListenerCompuesto);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextFieldToStirng = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jCheckBoxCustom = new javax.swing.JCheckBox();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButtonAplicarToString = new javax.swing.JButton();
        jButtonDelToString = new javax.swing.JButton();
        jTabbedPanePropiedades = new javax.swing.JTabbedPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListPropiedadesSimples = new javax.swing.JList();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListPropiedadesCompuestas = new javax.swing.JList();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(JPanelOpcionesBeansAbstractList.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextFieldToStirng.setText(resourceMap.getString("jTextFieldToStirng.text")); // NOI18N
        jTextFieldToStirng.setName("jTextFieldToStirng"); // NOI18N
        jTextFieldToStirng.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldToStirngFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldToStirngFocusLost(evt);
            }
        });

        jLabel2.setBackground(resourceMap.getColor("jLabel2.background")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabel2.setName("jLabel2"); // NOI18N
        jLabel2.setOpaque(true);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setBorderPainted(false);
        jToolBar1.setName("jToolBar1"); // NOI18N

        jCheckBoxCustom.setText(resourceMap.getString("jCheckBoxCustom.text")); // NOI18N
        jCheckBoxCustom.setFocusable(false);
        jCheckBoxCustom.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBoxCustom.setName("jCheckBoxCustom"); // NOI18N
        jCheckBoxCustom.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBoxCustom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxCustomActionPerformed(evt);
            }
        });
        jToolBar1.add(jCheckBoxCustom);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(JPanelOpcionesBeansAbstractList.class, this);
        jButtonAplicarToString.setAction(actionMap.get("aplicarToStringPersonlaizado")); // NOI18N
        jButtonAplicarToString.setFocusable(false);
        jButtonAplicarToString.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonAplicarToString.setName("jButtonAplicarToString"); // NOI18N
        jButtonAplicarToString.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButtonAplicarToString);

        jButtonDelToString.setAction(actionMap.get("limpiarToString")); // NOI18N
        jButtonDelToString.setFocusable(false);
        jButtonDelToString.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonDelToString.setName("jButtonDelToString"); // NOI18N
        jButtonDelToString.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButtonDelToString);

        jTabbedPanePropiedades.setName("jTabbedPanePropiedades"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jListPropiedadesSimples.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "No Disponible" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jListPropiedadesSimples.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jListPropiedadesSimples.setName("jListPropiedadesSimples"); // NOI18N
        jScrollPane2.setViewportView(jListPropiedadesSimples);

        jTabbedPanePropiedades.addTab("Propiedades Simples", jScrollPane2);

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jListPropiedadesCompuestas.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "No Disponible" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jListPropiedadesCompuestas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jListPropiedadesCompuestas.setName("jListPropiedadesCompuestas"); // NOI18N
        jScrollPane1.setViewportView(jListPropiedadesCompuestas);

        jTabbedPanePropiedades.addTab("Propiedades Compuestas", jScrollPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPanePropiedades, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldToStirng, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE))
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPanePropiedades, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldToStirng, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldToStirngFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldToStirngFocusGained
        if(jTextFieldToStirng.getText().equals("Seleccione una Propiedad o Personalice el Método a su Gusto.")){
            jTextFieldToStirng.setText("");
        }
    }//GEN-LAST:event_jTextFieldToStirngFocusGained

    private void jTextFieldToStirngFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldToStirngFocusLost
        if(jTextFieldToStirng.getText().isEmpty()){
            jTextFieldToStirng.setText("Seleccione una Propiedad o Personalice el Método a su Gusto.");
        }
    }//GEN-LAST:event_jTextFieldToStirngFocusLost

    private void jCheckBoxCustomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxCustomActionPerformed
        this.jButtonAplicarToString.setEnabled(jCheckBoxCustom.isSelected());
        this.jButtonDelToString.setEnabled(jCheckBoxCustom.isSelected());        
    }//GEN-LAST:event_jCheckBoxCustomActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAplicarToString;
    private javax.swing.JButton jButtonDelToString;
    private javax.swing.JCheckBox jCheckBoxCustom;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JList jListPropiedadesCompuestas;
    private javax.swing.JList jListPropiedadesSimples;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPanePropiedades;
    private javax.swing.JTextField jTextFieldToStirng;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Action
    public void limpiarToString() {
        jTextFieldToStirng.setText("");
        objComponenteDistribuidor.getObjComponenteBeans().setModo(ComponenteBeans.TO_STRING_SUPER);
    }

    @Action
    public void aplicarToStringPersonlaizado() {
        if(jTextFieldToStirng.getText().isEmpty() ||
                jTextFieldToStirng.getText().equals("Seleccione una Propiedad o Personalice el Método a su Gusto.")){
            UtilRender.msgAdvertencia("No ha Configurado el Metodo.");
            return;
        }
        objComponenteDistribuidor.getObjComponenteBeans().setModo(ComponenteBeans.TO_STRING_STRING);
        objComponenteDistribuidor.getObjComponenteBeans().setToString(jTextFieldToStirng.getText());
    }
}
